package zzl;

import java.nio.channels.SelectionKey;

/**
 * @ClassName TestSelectionKeyCalc
 * @Description 这四种事件用SelectionKey的四个常量来表示：
 * @Author zhangzeli
 * @Version 1.0
 * @Date 2019/3/5-10:55
 **/
public class TestSelectionKeyCalc {

    public static void main(String[] args) {

        System.out.println("读："+SelectionKey.OP_READ);
        System.out.println("写："+SelectionKey.OP_WRITE);
        System.out.println("连："+SelectionKey.OP_CONNECT);
        System.out.println("接："+SelectionKey.OP_ACCEPT);
        int interestSet = SelectionKey.OP_READ | SelectionKey.OP_WRITE;
        System.out.println(interestSet);
        boolean isInterestedInAccept  = (interestSet & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT;
        boolean isInterestedInConnect = (interestSet & SelectionKey.OP_CONNECT)== SelectionKey.OP_CONNECT;
        boolean isInterestedInRead    = (interestSet & SelectionKey.OP_READ)== SelectionKey.OP_READ;
        boolean isInterestedInWrite   = (interestSet & SelectionKey.OP_WRITE)== SelectionKey.OP_WRITE;
        System.out.println(isInterestedInAccept);
        System.out.println(isInterestedInConnect);
        System.out.println(isInterestedInRead);
        System.out.println(isInterestedInWrite);
    }
}
